import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    user_name: '',
    bookarr: [],
    girlarr: [],
    boyarr: [],
    lookarr: [],
    searchVal: "",
    itemVal: '',
    username:[],
    password:[],
    logged_in:false
  },
  mutations: {
    setname(state, user_name) {
      state.user_name = user_name
    },
    setbook(state, bookarr) {
      state.bookarr = bookarr
    },
    setgirl(state, girlarr) {
      state.girlarr = girlarr
    },
    setboy(state, boyarr) {
      state.boyarr = boyarr
    },
    setLook(state, look) {
      state.lookarr = look;
    },
    setVal(state, searchVal) {
      state.searchVal = searchVal;
      // window.localStorage.setItem('search', searchVal)
    },
    setItem(state, val) {
      state.itemVal = val;
    },
    setusername(state,username) {
      state.username=username;
    },
    setpassword(state,password){
      state.password=password;
    }
  },
  getters: {
    getname(state) {
      return state.user_name
    },
    getbook(state) {
      return state.bookarr
    },
    getgirl(state) {
      return state.girlarr
    },
    getboy(state) {
      return state.boyarr
    },
    getVal(state) {
      return state.searchVal
    }
  },
  actions: {
    ADDCART_DATA(context, item) {
      //  这里的item就是由页面传过来的对象（即你点击的商品的每一个对象）
      // =========  context.commit('需要触发的Mutation函数',要传的参数)
      context.commit('ADDCART_DATA', item)
    },
    setname(context) {
      context.commit("setname")
    },
    setbook(context) {
      context.commit("setbook")
    },
    setgirl(context) {
      context.commit("setgirl")
    },
    setboy(context) {
      context.commit("setboy")
    },
    setLook(context) {
      context.commit("setLook")
    },
    setVal(context) {
      context.commit("setVal")
    },
    setItem(context) {
      context.commit("setItem")
    },
    setusername(context,username) {
      context.commit("setusername",username)
    },
    setpassword(context,password) {
      context.commit("setpassword",password)
    }
  }
})

export default store